package club.banyuan.reserve.service;

import club.banyuan.reserve.consts.AppConst;
import club.banyuan.reserve.mapper.UserMapper;
import club.banyuan.reserve.model.User;
import club.banyuan.reserve.model.UserExample;
import club.banyuan.reserve.vo.UserVo;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HanChao
 * 描述信息：
 */
@Service
public class AdminUserServiceImpl implements AdminUserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserVo> showUserinfo() {

        List<User> userList = userMapper.selectByExample(new UserExample());

        List<UserVo> list = new ArrayList<>();
        for (User u: userList) {

            UserVo user = new UserVo();
            user.setId(u.getId());
            user.setUsername(u.getUsername());
            user.setNickname(u.getNickname());
            user.setEnabled(u.getEnabled());
            user.setCreatedAt(DateUtil.format(u.getCreatedAt(), AppConst.FORMAT_YMD_HM));

            list.add(user);
        }

        return list;
    }
}
